;
(function () {
    Vue.component('tree-row', {
        template:   `<div style="padding-left:17px">
                        <div class="PS-box" v-for="(item,index) in  model">
                            <ul class="PS-title"  @click="getchild(item,item.hasChild,item.showChild)">
                                <li>
                                    <span  style='width:24px;height:20px'>
                                        <span v-if="item.hasChild == 'Y'"><span :class="item.showChild == false ?'icon-Gm-prefix':'icon-GMopen'"   ></span></span>
                                    </span>   
                                    <span style="cursor: pointer">{{item.name}}</span>
                                </li>
                                <li class="switch" :class="orgp.indexOf(item.privilegeList[0].privilegeId) != -1?'switch-on':'switch-off'" @click.stop="switchpri(item.privilegeList[0].privilegeId,item.code)">
                                    <span class="yuan"></span>
                                </li>
                            </ul>
                            <tree-row  
                                :model="item.children"
                                :orgp="orgp"  
                                @getchild="getchild" 
                                @switchpri="switchpri" 
                                v-if="item.showChild">
                            </tree-row>
                        </div>
                    </div> `,
        props: {
            model:[Array],
            orgp:[Array],
        },
        data() {
            return {
                
            }
        },
        methods: {
            getchild(item,type){
                if(item.children.length){
                    item.showChild = !item.showChild
                }else{
                    this.$emit('getchild',item,type)
                    item.showChild = true
                }
            },
            switchpri(id,code){
                this.$emit('switchpri',id,code)
            }   
        },
    })
})()

